﻿using Autofac.Core;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
using System;
using WaterCloud.Code;
using WaterCloud.Domain.Entity.STZBManage;
using WaterCloud.Service.STZBManage;

namespace WaterCloud.Web.Areas.STZBManage.Controllers
{
    /// <summary>
    /// 武器管理控制器
    /// </summary>
    [Area("STZBManage")]
    public class WeaponsController : BaseController
    {
        public WeaponsService _service { get; set; }

        /// <summary>
        /// 添加或修改武器信息
        /// </summary>
        /// <param name="weapons">参数</param>
        /// <returns></returns>
        [HttpPost]
        [HandlerAjaxOnly]
        public async Task<ActionResult> SubmitForm(Weapons weapons)
        {
            try
            {
                await _service.AddOrDetails(weapons);
                return await Success("操作成功。", "", "");
            }
            catch (Exception ex)
            {
                return await Error(ex.Message, "", "");
            }
        }

        /// <summary>
        /// 根据id查询武器信息
        /// </summary>
        /// <param name="id">数据id</param>
        /// <returns></returns>
        [HttpGet]
        [HandlerAjaxOnly]
        public async Task<ActionResult> GetFormJson(int id)
        {
            var data = await _service.GetFormJson(id);
            return Content(data.ToJson());
        }

    }
}
